﻿using System;
using System.Collections.Generic;
using System.Runtime.InteropServices;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;
using System.Windows.Media;

namespace SpecialKey
{
    /// <summary>
    /// SkItem.xaml 的交互逻辑
    /// </summary>
    public partial class SkItem : UserControl
    {
        public SkItem()
        {
            InitializeComponent();
        }


        public string Class { get { return lbClass.Content as string; } set { lbClass.Content = value; } }
        public string Title { get { return lbTitle.Content as string; } set { lbTitle.Content = value; } }
        public int Id { get; set; }

        public string WorkingSet { get { return lbSize.Content as string; } set { lbSize.Content = value; } }

        public int Handle { get; set; }

        public int Mark
        {
            get { return mark; }
            set
            {
                mark = value;
                if (mark == 1)
                {
                    Background = new SolidColorBrush(Colors.LightGreen);
                    btnMark.Content = "解除";
                }
            }
        }
        private int mark;

        private void UserControl_MouseLeave(object sender, MouseEventArgs e)
        {
            if (Mark != 1)
                Background = new SolidColorBrush(Colors.White);
        }




        private void UserControl_MouseMove(object sender, MouseEventArgs e)
        {
            if (Mark != 1)
                Background = new SolidColorBrush(Colors.LightSkyBlue);
        }

        private void lbTitle_MouseDoubleClick(object sender, MouseButtonEventArgs e)
        {
            Clipboard.SetText(Title);
        }


        public static Dictionary<int, SkSource> ProcessIds = new Dictionary<int, SkSource>();

        private void Button_Click(object sender, RoutedEventArgs e)
        {
            if (btnMark.Content.ToString() == "标记")
            {
                ProcessIds.Add(Id, new SkSource { Handle = IntPtr.Zero, Title = Title });
                BorderThickness = new Thickness(1);
                Mark = 1;
                btnMark.Content = "解除";
            }
            else
            {
                Mark = 0;
                ProcessIds.Remove(Id);
                BorderThickness = new Thickness(0);
                btnMark.Content = "标记";
            }
        }
    }


    public class SkSource
    {
        public IntPtr Handle { get; set; }
        public string Title { get; set; }
    }
}
